package com.burgeon.backend.Rest.Tool;
/**
 * 获取用户信息
 */


import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class GetEMP extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public GetEMP(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public List getData(String mes) throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(mes),url);

        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        ArrayList list = new ArrayList();

        for (int i=0;i<jsonArray.length();i++){
            HashMap map = new HashMap();

            String name = jsonArray.getJSONArray(i).getString(0);
            String id = jsonArray.getJSONArray(i).getString(1);

            map.put("name",name);
            map.put("id",id);

            list.add(map);
        }

        return list;
    }

    private MultiValueMap Data(String name) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("NAME");
        columns.add("ID");

        params.put("columns", columns);
        params.put("table", "C_V_EMPLOYEE");//表名

        HashMap paramss = new HashMap();
        HashMap expr1 = new HashMap();
        expr1.put("column","ISACTIVE");
        expr1.put("condition","Y");
        HashMap expr2 = new HashMap();
        expr2.put("column","'C_STORE_ID;NAME'");
        expr2.put("condition",name);

        paramss.put("combine","and");
        paramss.put("expr1",expr1);
        paramss.put("expr2",expr2);

        params.put("params",paramss);
        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        GetEMP g = new GetEMP("59.110.28.94:90","nea@burgeon.com.cn","burgeon55321");
        try {
            System.err.println(g.getData("远洋AVVN"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
